package servlet;

import bean.Course;
import dao.CourseDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletUpdateCourse extends HttpServlet {
    protected static Course receiveCourseObj(HttpServletRequest req) {
        Course course = new Course();

        String info = req.getParameter("info");
        String week = req.getParameter("week");

        int lessonStart = Integer.parseInt(req.getParameter("lessonStart"));
        int lessonEnd = Integer.parseInt(req.getParameter("lessonEnd"));
        int id = Integer.parseInt(req.getParameter("id"));

        String day_of_week = req.getParameter("day_of_week");
        String date = req.getParameter("date");
        String teacher = req.getParameter("teacher");
        String place = req.getParameter("place");

        course.setCourseInfo(info);
        course.setWeek(week);
        course.setLessonStart(lessonStart);
        course.setLessonEnd(lessonEnd);
        course.setId(id);

        course.setDay_of_week(day_of_week);
        course.setDate(date);
        course.setTeacher(teacher);
        course.setPlace(place);


        return course;
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Course course = receiveCourseObj(req);

        System.out.println(course);
        new CourseDao().update(course);
        resp.sendRedirect("index");

    }
}// 我知道了
